// pages/seller/add.js
var server = require('../../utils/server');
Page({
  data:{
    region: ['', '', ''],
    province:'',
    first_id:'',
    second_id:'',
    type:0,
    value:'',
    name:'',
    mobile:'',
    addressInfo:'',
    mianji:'',
    pspt_num:'',
    sellername:'',
    fanwei:0,
    weixin:'',
    qq:'',
    sellerbiref:'',
    imgurl:'',
  },
  geren:function(){
    this.setData({
      type: 0
    })
  },
  qiye:function(){
    this.setData({
      type:1
    }) 
  },
  sumbit:function(){
      let that = this
      let shop_cate = that.data.first_id + '-' +that.data.second_id
    if(that.data.value != 'sure'){
       wx.showToast({
          title: '请同意入驻协议',
          icon: 'none'
        });
    } 
    else if (!that.data.name){
         wx.showToast({
          title: '请输入你的真实姓名',
          icon: 'none'
        })
    }
    else if (!that.data.mobile) {
      wx.showToast({
        title: '请输入你的联系电话',
        icon: 'none'
      })
    }
    else if (!that.data.province) {
       wx.showToast({
        title: '请选择店铺地址',
        icon: 'none'
      })
    }
    else if (!that.data.addressInfo) {
       wx.showToast({
        title: '请输入详细地址',
        icon: 'none'
      })
    }
    else if (!that.data.mianji) {
      wx.showToast({
        title: '请输入营业面积',
        icon: 'none'
      })
    }
    else if (!that.data.second_id){
        wx.showToast({
          title: '请输入商家分类',
          icon: 'none'
        })
    }
    else if (!that.data.sellername) {
       wx.showToast({
        title: '请输入店铺名称',
        icon: 'none'
      })
    }
    else{
      let data={
        username: getApp().globalData.username,
        token: getApp().globalData.token,
        name: that.data.name,
        mobile: that.data.mobile,
        province: that.data.province,
        mianji: that.data.mianji,
        shop_cate: shop_cate,
        shop_name: that.data.sellername,
        lng: getApp().globalData.lng,
        lat: getApp().globalData.lat,
        pspt_num: that.data.pspt_num,
        pspt_hand:'',
        address: that.data.addressInfo,
        seller_photo:'',
        is_quanguo: that.data.fanwei,
        wx_num: that.data.weixin,
        qq_num: that.data.qq,
        brief: that.data.sellerbiref,
        open_mobile:'',
        weixin_pay:'',
        alipay_pay:''
      };
    //   server.postJSON('/seller/card',data,(res)=>{
    //     console.log(res)
    //   })
        server.send('/seller/card', 'POST',data).then (res=> {
            console.log(res)
        })
    }
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数 
    
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    let that = this
    wx.getStorage({
      key: 'first_id',
      success: function (res) {
        that.setData({
          first_id: res.data
        })
      }
    });
    wx.getStorage({
      key: 'second_id',
      success: function (res) {
        that.setData({
          second_id: res.data
        })
      }
    });
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  setname:function(e){
    //联系人
    let name = e.detail.value;
    this.setData({ name: name});
  },
  setmobile: function (e) {
    //联系电话
    let mobile = e.detail.value;
    this.setData({ mobile: mobile });
  },
  setAddressInfo: function (e) {
    //详细地址
    let addressInfo = e.detail.value;
    this.setData({ addressInfo: addressInfo });
  },
  setmianji: function (e) {
    //营业面积
    let mianji = e.detail.value;
    this.setData({ mianji: mianji });
  },
  setpsptNum: function (e) {
    //营业执照号
    let pspt_num = e.detail.value;
    this.setData({ pspt_num: pspt_num });
  },
  setpsptimg: function (e) {
    //营业执照电子版
    console.log('营业执照电子版')
  },
  setsellerimg: function (e) {
    //店铺门头
    // console.log('店铺门头')
    let that = this
    wx:wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function(res) {
        // console.log()
        let imgurl = res.tempFilePaths[0]
          that.setData({
            imgurl: imgurl,
          })
          wx.uploadFile({
            url: '',
            filePath: '',
            name: '',
          })
      },
    })
  },
  setweixinimg: function (e) {
    //微信收款码
    console.log('微信收款码')
  },
  setzhifubaoimg: function (e) {
    //支付宝收款码
    console.log('支付宝收款码')
  },
  setsellertype: function (e) {
    //商家分类
    wx.navigateTo({
      url: 'shoptype/type',
    })
  },
  setSellerName: function (e) {
    //店铺名称
    let sellername = e.detail.value;
    this.setData({ sellername: sellername });
  },
  setfanwei: function (e) {
    //销售范围
    
    let fanwei = e.detail.value;
    this.setData({ fanwei: fanwei });
    console.log(fanwei)
  },
  setweixin: function (e) {
    //微信号
    let weixin = e.detail.value;
    this.setData({ weixin: weixin });
  },
  setqq: function (e) {
    //QQ号
    let qq = e.detail.value;
    this.setData({ qq: qq });
  },
  setSellerBiref: function (e) {
    //商家简介
    let sellerbiref = e.detail.value;
    this.setData({ sellerbiref: sellerbiref });
  },
  setzuobiao: function (e) {
    //添加地图位置
    wx.chooseLocation({
      success: function(res) {
        let lat = res.latitude
        let lng = res.longitude
        getApp().globalData.lng = lng
        getApp().globalData.lat = lat
      }
    });
  },
  radioChange:function(e){
    let value = e.detail.value;
    this.setData({ value: value });
  },
  bindRegionChange:function(e){
    let region = e.detail.value
    let province = e.detail.code[0] + '/' + e.detail.code[1] + '/' + e.detail.code[2]
    this.setData({
      region: region,
      province: province
    })
  },
})